//
//  Stack.m
//  iBole
//
//  Created by Tao Chen on 12-3-13.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
/*This file is part of iBole.
 
 iBole is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 iBole is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */

#import "Stack.h"

@implementation Stack
{
    NSMutableArray * array;
}
-(id)init
{
    if(self = [super init])
    {
        array = [[NSMutableArray alloc] init];
    }
    return self;
}
-(void)dealloc
{
    [array release];
    [super dealloc];
}
-(void) push:(NSString*)node
{
    [array addObject:node];
}
-(NSString*) pop
{
    NSString * res = [array lastObject];
    [res retain];
    [array removeLastObject];
    return [res autorelease];
}
-(NSString*) top
{
    return [array lastObject];
}
-(bool) hasObject:(NSString*)object
{
    for (NSString* item in array) {
        if ([item isEqualToString:object]) {
            return YES;
        }
    }
    return NO;
}
@end
